@using BTCPayServer.Abstractions.Contracts
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model UsersViewModel.UserViewModel
@inject IFileService FileService
@{
    ViewData.SetLayoutModel(new(nameof(ServerNavPages.Users), Model.Email));
    var canUpload = await FileService.IsAvailable();
}

<form method="post" enctype="multipart/form-data">
    <div class="sticky-header">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a asp-action="ListUsers" text-translate="true">Users</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page" text-translate="true">User</li>
            </ol>
            <h2>@ViewData["Title"]</h2>
        </nav>
		<button id="page-primary" name="command" type="submit" class="btn btn-primary" value="Save" text-translate="true">Save</button>
    </div>
    <partial name="_StatusMessage" />

    @if (!string.IsNullOrEmpty(Model.InvitationUrl))
    {
        <div class="payment-box mx-0 mb-4">
            <div class="qr-container">
                <vc:qr-code data="@Model.InvitationUrl" />
            </div>
            <div class="input-group mt-3">
                <div class="form-floating">
                    <vc:truncate-center text="@Model.InvitationUrl" padding="15" elastic="true" classes="form-control-plaintext" id="InvitationUrl"/>
                    <label for="InvitationUrl" text-translate="true">Invitation URL</label>
                </div>
            </div>
        </div>
    }

    <div class="form-group">
        <label asp-for="Name" class="form-label"></label>
        <input asp-for="Name" class="form-control" />
        <span asp-validation-for="Name" class="text-danger"></span>
    </div>
    <div class="form-group">
        <div class="d-flex align-items-center justify-content-between gap-2">
            <label asp-for="ImageFile" class="form-label"></label>
            @if (!string.IsNullOrEmpty(Model.ImageUrl))
            {
            <button type="submit" class="btn btn-link p-0 text-danger" name="RemoveImageFile" value="true">
                <vc:icon symbol="cross" />
                <span text-translate="true">Remove</span>
            </button>
            }
        </div>
        @if (canUpload)
        {
            <div class="d-flex align-items-center gap-3">
                <input asp-for="ImageFile" type="file" class="form-control flex-grow">
                @if (!string.IsNullOrEmpty(Model.ImageUrl))
                {
                    <img src="@Model.ImageUrl" alt="Profile picture" class="profile-picture" />
                }
            </div>
            <span asp-validation-for="ImageFile" class="text-danger"></span>
        }
        else
        {
            <input asp-for="ImageFile" type="file" class="form-control" disabled>
            <div class="form-text">@ViewLocalizer["In order to upload, a {0} must be configured.", Html.ActionLink(StringLocalizer["file storage"], "Files", "UIServer")]</div>
        }
    </div>
    <div class="form-check my-3">
        <input asp-for="IsAdmin" type="checkbox" class="form-check-input" />
        <label asp-for="IsAdmin" class="form-check-label" text-translate="true">User is admin</label>
    </div>
    @if (Model.Approved.HasValue)
    {
        <div class="form-check my-3">
            <input id="Approved" name="Approved" type="checkbox" value="true" class="form-check-input" @(Model.Approved.Value ? "checked" : "") />
            <label for="Approved" class="form-check-label" text-translate="true">User is approved</label>
        </div>
        <input name="Approved" type="hidden" value="false">
    }
    @if (Model.EmailConfirmed.HasValue)
    {
        <div class="form-check my-3">
            <input id="EmailConfirmed" name="EmailConfirmed" value="true" type="checkbox" class="form-check-input" @(Model.EmailConfirmed.Value ? "checked" : "") />
            <label for="EmailConfirmed" class="form-check-label" text-translate="true">Email address is confirmed</label>
        </div>
        <input name="EmailConfirmed" type="hidden" value="false">
    }
</form>
